package com.cn.jinl.controller;

import com.cn.jinl.api.ISysItemService;
import com.cn.jinl.domain.SysItem;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @类名:SysItemController
 * @包名:com.cn.jinl.controller
 * @作者:chenxingliang
 * @时间:2022-11-23 17:24
 * @版本:1.0.0
 */

@Controller
@RequestMapping("/sysItem")
public class SysItemController {

    @Autowired
    private ISysItemService sysItemService;


    @ResponseBody
    @RequestMapping("/getMgItemList/{frontToken}")
    public JsonResponse<List<SysItem>> getMgItemList(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemList(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getMgItemSelect/{frontToken}")
    public JsonResponse<List<SysItem>> getMgItemSelect(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemSelect(queryForm);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getAllMgItemList/{frontToken}")
    public JsonResponse<List<SysItem>> getAllMgItemList(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getAllMgItemList();
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getMgItemDefaultValue/{frontToken}")
    public JsonResponse<String> getMgItemDefaultValue(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.getMgItemDefaultValue(mgItem);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/addMgItemDetail/{frontToken}")
    public JsonResponse<String> addMgItemDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addMgItemDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateMgItemDetail/{frontToken}")
    public JsonResponse<String> updateMgItemDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateMgItemValue/{frontToken}")
    public JsonResponse<String> updateMgItemValue(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemValue(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deleteMgItemDetail/{frontToken}")
    public JsonResponse<String> deleteMgItemDetail(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.deleteMgItemDetail(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/api/getMgItemSelectByType")
    public JsonResponse<List<SysItem>> getMgItemSelectByType(String type) throws Exception {
        JsonResponse<List<SysItem>> response = new JsonResponse<List<SysItem>>();
        List<SysItem> mgItems = sysItemService.getMgItemSelectByType(type);
        response.setResult(mgItems);
        response.setSuccess(true);
        return response;
    }


    /**
     * @author : Huiyan feng
     * @date   : 2023/12/6
     * @param  : [frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.util.Map<java.lang.String,java.util.List<com.cn.jinl.domain.SysItem>>>
     * @description : getCategoryMap 基础数据--物料下拉框联动
     */
    @ResponseBody
    @RequestMapping("/getCategoryMap/{frontToken}")
    public JsonResponse<Map<String,List<SysItem>>> getCategoryMap(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<Map<String,List<SysItem>>> response = new JsonResponse<>();
        Map<String,List<SysItem>> result = sysItemService.getCategoryMap();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    /**
     * @author : Huiyan feng
     * @date   : 2024/2/2
     * @param  : [mgItem, frontToken]
     * @return : com.cn.jinl.utils.JsonResponse<java.lang.String>
     * @description : 挤塑机号
     */
    @ResponseBody
    @RequestMapping("/updateMgItemCodeDetail/{frontToken}")
    public JsonResponse<String> updateMgItemCodeDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.updateMgItemCodeDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/addMgItemCodeDetail/{frontToken}")
    public JsonResponse<String> addMgItemCodeDetail(SysItem mgItem,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sysItemService.addMgItemCodeDetail(mgItem);
        return CommonUtil.getResponseData(response,result);
    }

}
